﻿using System;
using System.Globalization;

namespace SuppKids.Core.Exceptions
{
    public class ErrorCodeException : Exception
	{
		private const string errorCodeMessageTemplate = "Error with code: {0}.{1}";
		private readonly int errorCode;
		private readonly int errorSubCode;

		public ErrorCodeException(int errorCode, int errorSubCode, string message, Exception innerException)
			: base(string.Format(errorCodeMessageTemplate, errorCode, errorSubCode) + message, innerException)
		{
			this.errorCode = errorCode;
			this.errorSubCode = errorSubCode;
		}

		public ErrorCodeException(int errorCode, int errorSubCode, Exception innerException)
			: base(string.Format(CultureInfo.InvariantCulture, errorCodeMessageTemplate, errorCode, errorSubCode), innerException)
		{
			this.errorCode = errorCode;
			this.errorSubCode = errorSubCode;
		}

		public ErrorCodeException(int errorCode, int errorSubCode, string errorMessage)
			: base(errorMessage ?? string.Empty)
		{
			this.errorCode = errorCode;
			this.errorSubCode = errorSubCode;
		}

		public ErrorCodeException(int errorCode, int errorSubCode)
			: base(string.Format(errorCodeMessageTemplate, errorCode, errorSubCode))
		{
			this.errorCode = errorCode;
			this.errorSubCode = errorSubCode;
		}

		public virtual int ErrorCode
		{
			get
			{
				return this.errorCode;
			}
		}

		public virtual int ErrorSubCode
		{
			get
			{
				return this.errorSubCode;
			}
		}

		public override string ToString()
		{
			return string.Format(CultureInfo.InvariantCulture, errorCodeMessageTemplate, errorCode, errorSubCode);
		}
	}
}
